#include <iostream>
#include <string>
using namespace std;
struct TwoStack{
	int siz;

	int top1;
	int top2;
	int * arr;
	void push(int index, int x)
	{
		if (top1 >= top2 - 1)
		{
			cout << "you fool!" << endl;
			return;
		}
			

		if (index == 1)
		{
			arr[++top1] = x;
		}
		else if (index == 2)
		{
			arr[--top2] = x;
		}
	}
	
	bool pop(int index, int *x)
	{
		if (index == 1)
		{
			if (top1 == -1)
			{
				cout << "stack" << index << " is  empty" << endl;
				return false;
			}
			else{
				//cout << "stack" << index << " is  empty" << endl;
				*x = arr[top1];
				--top1;
				return true;
			}

		}
		else if (index == 2)
		{
			if (top2 == siz)
			{
				cout << "stack" << index << " is  empty" << endl;
				return false;
			}
			else{
				*x = arr[top2];
				++top2;
				return true;
			}
		}
	}
	

	TwoStack(int s) :siz(s), top1(-1), top2(s)
	{
	
		arr = new int(s);
	}
	
	~TwoStack()
	{
		delete arr;
	}




};



int main()
{
	TwoStack ts(2);
	string com;
	int xin, xout, index;
	while (cin >> com)
	{
		if (com == "push")
		{
			cin >> index >> xin;
			ts.push(index, xin);
			
		}
		else if (com == "pop")
		{
			cin >> index;
			if(ts.pop(index, &xout))
				cout << "get " << xout << endl;
		}
		else if(com == "q"){
			break;
		}
	}

	return 0;
}